Skip to content

sanitise the invocation id path param with a safe fallback#47485

Open
alhudz wants to merge 1 commit into
Azure:mainfrom
alhudz:invocation-id-sanitise-fallback
Open

sanitise the invocation id path param with a safe fallback#47485
alhudz wants to merge 1 commit into
Azure:mainfrom
alhudz:invocation-id-sanitise-fallback

Conversation

@alhudz

@alhudz alhudz commented Jun 13, 2026

Copy link
Copy Markdown

Description

GET /invocations/{id} and the POST /invocations/{id}/cancel variant both run through _traced_invocation_endpoint, which is meant to validate the id with _sanitize_id before it reaches the x-agent-invocation-id response header and the request-scoped log and span fields.

Repro: request GET /invocations/bad~id (a character outside _VALID_ID_RE), or an id longer than _MAX_ID_LENGTH; the raw value comes straight back in the x-agent-invocation-id response header.
Cause: the call is _sanitize_id(raw_invocation_id, raw_invocation_id), so the rejected value is its own fallback and the length and character checks can never drop anything. _create_invocation_endpoint passes a generated UUID instead.
Fix: fall back to a fresh UUID, matching the create path, so a malformed id never reaches the header or the logs. Added a regression test for the invalid-character and over-length cases plus a valid-id passthrough.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings June 13, 2026 18:08
@github-actions github-actions Bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/* labels Jun 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution @alhudz! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Prevents malformed invocation_id path parameters from being reflected into the x-agent-invocation-id response header by sanitizing to a generated fallback, and adds regression tests plus a version/changelog bump.

Changes:

  • Sanitize invocation_id from path params using a generated UUID fallback in traced invocation endpoints.
  • Add async tests asserting malformed/overlong IDs are not echoed into response headers.
  • Bump package version to 1.0.0b6 and document the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
sdk/agentserver/azure-ai-agentserver-invocations/azure/ai/agentserver/invocations/_invocation.py Switches path invocation_id sanitization fallback to a generated UUID to prevent reflection of malformed IDs.
sdk/agentserver/azure-ai-agentserver-invocations/tests/test_invocation_id_sanitization.py Adds regression coverage for invocation id sanitization in response headers.
sdk/agentserver/azure-ai-agentserver-invocations/azure/ai/agentserver/invocations/_version.py Bumps the prerelease version to 1.0.0b6.
sdk/agentserver/azure-ai-agentserver-invocations/CHANGELOG.md Adds an Unreleased 1.0.0b6 entry describing the fix.

Comment on lines +39 to +40
@pytest.mark.asyncio
async def test_invalid_char_id_not_reflected_in_header():
Comment on lines +34 to +36
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
resp = await client.get(f"/invocations/{path_id}")
return resp.headers[_HEADER]

from azure.ai.agentserver.invocations import InvocationAgentServerHost
from azure.ai.agentserver.invocations._constants import InvocationConstants
from azure.ai.agentserver.invocations._invocation import _MAX_ID_LENGTH, _VALID_ID_RE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants